home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-03 | 6.0 KB | 170 lines | [TEXT/R*ch] |
- (* test/bytechar.sml -- test cases for Byte and Char, suitable for ASCII
- PS 1994-12-10, 1995-05-11 *)
-
- use "auxil.sml";
-
- local
-
- in
- val test1 = checkrange (0,255)
- (fn i => (Word8.wordToInt o Byte.ord o Byte.chr
- o Word8.intToWord) i = i);
-
- val test2 = checkrange (0,Char.maxOrd)
- (fn i => (Word8.wordToInt o Byte.ord o Char.chr) i = i);
-
- val test3 = checkrange (0,255)
- (fn i => (Char.ord o Byte.chr o Word8.intToWord) i = i);
-
- val test4 = checkrange (0, Char.maxOrd)
- (fn i => (Char.ord o Char.chr) i = i);
-
- val test5 = (Char.chr ~1 seq "WRONG") handle Char.Chr => "OK" | _ => "WRONG";
-
- val test6 = (Char.chr (Char.maxOrd+1) seq "WRONG")
- handle Char.Chr => "OK" | _ => "WRONG";
-
- val test7 = check("" = Byte.string (Word8Vector.fromList []));
-
- val test8 =
- check("ABDC" = (Byte.string o Word8Vector.fromList o map Word8.intToWord)
- [65, 66, 68, 67]);
-
- val test9 = check("" = Byte.extract(Word8Array.fromList [], 0, SOME 0));
-
- local
- val arr = Word8Array.tabulate(10, fn i => Word8.intToWord(i+65))
- in
- val test10a = check("" = Byte.extract(arr, 0, SOME 0));
- val test10b = check("" = Byte.extract(arr, 10, SOME 0)
- andalso "" = Byte.extract(arr, 10, NONE));
- val test10c = check("BCDE" = Byte.extract(arr, 1, SOME 4));
- val test10d = (Byte.extract(arr, ~1, SOME 0) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test10e = (Byte.extract(arr, 11, SOME 0) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test10f = (Byte.extract(arr, 0, SOME ~1) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test10g = (Byte.extract(arr, 0, SOME 11) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test10h = (Byte.extract(arr, 10, SOME 1) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test10i = (Byte.extract(arr, ~1, NONE) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test10j = (Byte.extract(arr, 11, NONE) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- end
-
- val test18 = check(not (Char.contains "" (Char.chr 65))
- andalso not (Char.contains "aBCDE" (Char.chr 65))
- andalso (Char.contains "ABCD" (Char.chr 67))
- andalso not (Char.contains "" #"\000")
- andalso not (Char.contains "" #"\255")
- andalso not (Char.contains "azAZ09" #"\000")
- andalso not (Char.contains "azAZ09" #"\255"));
-
- val test19 = check(Char.notContains "" (Char.chr 65)
- andalso Char.notContains "aBCDE" (Char.chr 65)
- andalso not (Char.notContains "ABCD" (Char.chr 67))
- andalso Char.notContains "" #"\000"
- andalso Char.notContains "" #"\255"
- andalso Char.notContains "azAZ09" #"\000"
- andalso Char.notContains "azAZ09" #"\255");
-
- val test20 = check(Char.ord Char.maxChar = Char.maxOrd);
-
- local
- fun mycontains s c =
- let val stop = String.size s
- fun h i = i < stop andalso (c = String.sub(s, i) orelse h(i+1))
- in h 0 end;
-
- (* Check that p(c) = (mycontains s c) for all characters: *)
- fun equivalent p s =
- let fun h n =
- n > 255 orelse
- (p (chr n) = mycontains s (chr n)) andalso h(n+1)
- in h 0 end
-
- fun checkset p s = check'(fn _ => equivalent p s);
-
- val graphchars = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\
- \[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\
- \\128\129\130\131\132\133\134\135\136\137\138\139\140\141\
- \\142\143\144\145\146\147\148\149\150\151\152\153\154\155\156\
- \\157\158\159\160\161\162\163\164\165\166\167\168\169\170\171\
- \\172\173\174\175\176\177\178\179\180\181\182\183\184\185\186\
- \\187\188\189\190\191\192\193\194\195\196\197\198\199\200\201\
- \\202\203\204\205\206\207\208\209\210\211\212\213\214\215\216\
- \\217\218\219\220\221\222\223\224\225\226\227\228\229\230\231\
- \\232\233\234\235\236\237\238\239\240\241\242\243\244\245\246\
- \\247\248\249\250\251\252\253\254";
-
- val ascii = "\^@\^A\^B\^C\^D\^E\^F\^G\^H\t\n\^K\^L\^M\^N\^O\^P\
- \\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_\
- \ !\"#$%&'()*+,-./0123456789:;<=>?@\
- \ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\127"
-
- val lowerascii = "\^@\^A\^B\^C\^D\^E\^F\^G\^H\t\n\^K\^L\^M\^N\^O\^P\
- \\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_\
- \ !\"#$%&'()*+,-./0123456789:;<=>?@\
- \abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\127"
-
- val upperascii = "\^@\^A\^B\^C\^D\^E\^F\^G\^H\t\n\^K\^L\^M\^N\^O\^P\
- \\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_\
- \ !\"#$%&'()*+,-./0123456789:;<=>?@\
- \ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~\127"
-
- val allchars =
- let fun h 0 res = chr 0 :: res
- | h n res = h (n-1) (chr n :: res)
- in h 255 [] end
-
- open Char
- in
-
- val test21 =
- checkset isLower "abcdefghijklmnopqrstuvwxyz";
- val test22 =
- checkset isUpper "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- val test23 =
- checkset isDigit "0123456789";
- val test24 =
- checkset isAlpha "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- val test25 =
- checkset isHexDigit "0123456789abcdefABCDEF";
- val test26 =
- checkset isAlphaNum
- "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- val test27 =
- checkset isPrint (" " ^ graphchars)
- val test28 =
- checkset isSpace " \009\010\011\012\013";
- val test29 =
- checkset isGraph graphchars
- val test30 =
- checkset isAscii ascii
-
- val test31 =
- check'(fn _ => map toLower (explode ascii) = explode lowerascii)
- val test32 =
- check'(fn _ => map toUpper (explode ascii) = explode upperascii)
- val test33 =
- check'(fn _ =>
- map toUpper (explode graphchars)
- seq map toLower (explode graphchars)
- seq true)
-
- val test34a =
- check'(fn _ =>
- map pred (List.drop(allchars, 1)) = List.take(allchars, 255));
- val test34b = (pred #"\000" seq "WRONG")
- handle Chr => "OK" | _ => "WRONG";
- val test35a =
- check'(fn _ =>
- map succ (List.take(allchars, 255)) = List.drop(allchars, 1));
- val test35b = (succ #"\255" seq "WRONG")
- handle Chr => "OK" | _ => "WRONG";
- end
- end
-